package org.moda.functional.fp;

import java.util.function.Function;

public interface Applicative<A> extends Functor<A> {
    // (A, F[A => B]) => F[B]
    // 其实这里A就是this，实际上就是 F[A => B] => F[B]
    public <B> Applicative<B> apply(Applicative<Function<A, B>> fa);

    // B => F[B]
    public <B> Applicative<B> unit(B b);

    // (A, A => B) => F[B]
    // 其实这里A就是this，(A => B) => F[B]
    // 使用 unit 和 apply 实现 map
    @Override
    public default <B> Applicative<B> map(Function<A, B> abf) {
        return this.apply(unit(abf));
    }
}
